import {Button, Result} from 'antd';
import * as React from 'react';
import {useEffect} from 'react';
import {history, Link} from 'umi';

const Redirect: React.FC<any> = () => {
    const token = sessionStorage.getItem('token');
    const modules = sessionStorage.getItem('modules')
        ? JSON.parse(sessionStorage.getItem('modules') as string)
        : [];
    const path = token ? (modules.length ? modules[0]?.path : '/home') : '/login';
    // console.log('token', token);
    // console.log('modules', modules);
    // console.log('path', path);
    useEffect(() => {
        if (path) history.push(path);
    }, [path]);

    return !path ? (
        <Result
            status={403}
            title="403"
            subTitle="您未被授权任何功能菜单！"
            extra={
                <Button type="primary">
                    <Link to="/login">请联系管理员后，返回登录页</Link>
                </Button>
            }
        />
    ) : (
        <></>
    );
};

export default Redirect;
